<?php

use Illuminate\Database\Seeder;

class CpcDefault extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //
        $providers = [
            [
                'id'    =>  1,
                'type'  =>  0,
                'name'  =>  '自营',
                'identifier' =>  'default',
            ],
            [
                'id'    =>  2,
                'type'  =>  1,
                'name'  =>  '头条',
                'identifier' =>  'toutiao'
            ],
            [
                'id'    =>  3,
                'type'  =>  1,
                'name'  =>  '龙云',
                'identifier' =>  'yunlong'
            ],
        ];

        foreach ($providers as $key => $value) {
            $id = $value['id'];
            $provider = \App\Model\AdProvider::find($id);
            if (empty($provider)) {
                $provider = \App\Model\AdProvider::create($value);
            }
        }

        $positions = [
            [
                'id'    =>  1,
                'name'  =>  'feed大图',
                'identifier' =>  'feed_big',
            ],
            [
                'id'    =>  2,
                'name'  =>  '我的页面banner',
                'identifier' =>  'me_banner',
            ],
            [
                'id'    =>  3,
                'name'  =>  'feed流组图',
                'identifier' =>  'feed_group',
            ],
            [
                'id'    =>  4,
                'name'  =>  '新闻详情banner',
                'identifier' =>  'detail_banner',
            ],
            [
                'id'    =>  5,
                'name'  =>  '视频流大图',
                'identifier' =>  'video_big',
            ],
            [
                'id'    =>  6,
                'name'  =>  '视频详情',
                'identifier' =>  'videodetail_big',
            ],
            [
                'id'    =>  7,
                'name'  =>  '开屏',
                'identifier'    =>  'launch',
            ],
        ];
        foreach ($positions as $key => $value) {
            $id = $value['id'];
            $position = \App\Model\AdPosition::find($id);
            if (empty($position)) {
                $position = \App\Model\AdPosition::create($value);
            }
        }

        $configs = [
            [
                 "id" => 1,
                 "rank" => 0,
                 "ad_provider_id" => 1,
                 "ad_position_id" => 0,
                 "key" => "max_show_per_device_daily",
                 "value" => "6",
                 "action" => "return_provider",
            ],
            [
                 "id" => 2,
                 "rank" => 1,
                 "ad_provider_id" => 1,
                 "ad_position_id" => 0,
                 "key" => "min_show_daily",
                 "value" => "100",
                 "action" => "return_provider",
            ],
            [
                 "id" => 3,
                 "rank" => 2,
                 "ad_provider_id" => 2,
                 "ad_position_id" => 1,
                 "key" => "min_show_hourly",
                 "value" => "500",
                 "action" => "sort_by_ctr",
                 "created_at" => null,
                 "updated_at" => null,
            ],
            [
                 "id" => 4,
                 "rank" => 2,
                 "ad_provider_id" => 3,
                 "ad_position_id" => 1,
                 "key" => "min_show_hourly",
                 "value" => "500",
                 "action" => "sort_by_ctr",
                 "created_at" => null,
                 "updated_at" => null,
            ],     
            [
                 "id" => 5,
                 "rank" => 2,
                 "ad_provider_id" => 2,
                 "ad_position_id" => 2,
                 "key" => "min_show_hourly",
                 "value" => "500",
                 "action" => "sort_by_ctr",
                 "created_at" => null,
                 "updated_at" => null,
            ],
            [
                 "id" => 6,
                 "rank" => 2,
                 "ad_provider_id" => 3,
                 "ad_position_id" => 2,
                 "key" => "min_show_hourly",
                 "value" => "500",
                 "action" => "sort_by_ctr",
                 "created_at" => null,
                 "updated_at" => null,
            ],  
            [
                 "id" => 7,
                 "rank" => 2,
                 "ad_provider_id" => 2,
                 "ad_position_id" => 3,
                 "key" => "min_show_hourly",
                 "value" => "500",
                 "action" => "sort_by_ctr",
                 "created_at" => null,
                 "updated_at" => null,
            ],
            [
                 "id" => 8,
                 "rank" => 2,
                 "ad_provider_id" => 3,
                 "ad_position_id" => 3,
                 "key" => "min_show_hourly",
                 "value" => "500",
                 "action" => "sort_by_ctr",
                 "created_at" => null,
                 "updated_at" => null,
            ],   
            [
                 "id" => 9,
                 "rank" => 2,
                 "ad_provider_id" => 2,
                 "ad_position_id" => 4,
                 "key" => "min_show_hourly",
                 "value" => "500",
                 "action" => "sort_by_ctr",
                 "created_at" => null,
                 "updated_at" => null,
            ],
            [
                 "id" => 10,
                 "rank" => 2,
                 "ad_provider_id" => 3,
                 "ad_position_id" => 4,
                 "key" => "min_show_hourly",
                 "value" => "500",
                 "action" => "sort_by_ctr",
                 "created_at" => null,
                 "updated_at" => null,
            ], 
            [
                 "id" => 11,
                 "rank" => 2,
                 "ad_provider_id" => 2,
                 "ad_position_id" => 5,
                 "key" => "min_show_hourly",
                 "value" => "500",
                 "action" => "sort_by_ctr",
                 "created_at" => null,
                 "updated_at" => null,
            ],
            [
                 "id" => 12,
                 "rank" => 2,
                 "ad_provider_id" => 3,
                 "ad_position_id" => 5,
                 "key" => "min_show_hourly",
                 "value" => "500",
                 "action" => "sort_by_ctr",
                 "created_at" => null,
                 "updated_at" => null,
            ], 
            [
                 "id" => 13,
                 "rank" => 2,
                 "ad_provider_id" => 2,
                 "ad_position_id" => 6,
                 "key" => "min_show_hourly",
                 "value" => "500",
                 "action" => "sort_by_ctr",
                 "created_at" => null,
                 "updated_at" => null,
            ],
            [
                 "id" => 14,
                 "rank" => 2,
                 "ad_provider_id" => 3,
                 "ad_position_id" => 6,
                 "key" => "min_show_hourly",
                 "value" => "500",
                 "action" => "sort_by_ctr",
                 "created_at" => null,
                 "updated_at" => null,
            ], 
        ];
        foreach ($configs as $key => $value) {
            $id = $value['id'];
            $config = \App\Model\CpcConfig::find($id);
            if (empty($config)) {
                $config = \App\Model\CpcConfig::create($value);
            }
        }

        $costs = [
            [
                'id'    =>  1,
                'ad_provider_id'    =>  1,
                'cost'  =>  0.5
            ],
            [
                'id'    =>  2,
                'ad_provider_id'    =>  2,
                'cost'  =>  0.3
            ],
            [
                'id'    =>  3,
                'ad_provider_id'    =>  3,
                'cost'  =>  0.2
            ],
        ];
        foreach ($costs as $key => $value) {
            $id = $value['id'];
            $cost = \App\Model\AdCost::find($id);
            if (empty($cost)) {
                $cost = \App\Model\AdCost::create($value);
            }
        }
    }
}
